<?php
class ContactController extends Henry_Controller_Action
{
    public function init()
    {
        parent::init();
       $this->_helper->layout->setLayout('other');
    }
//    Array
//(
//    [controller] => contact
//    [action] => index
//    [module] => default
//    [hoten] => asdf
//    [congty] => asdf
//    [diachi] => asdf
//    [email] => asdf sadf
//    [dienthoai] => as dfsadf
//    [fax] => asd fs
//    [noidung] => adf asdf asdf
//)
//
//$config = array(
//'auth' => 'login',
//'username' => 'good username',
//'password' => 'good password',
//'port' => 587,
//'ssl' => 'tls'
//);
    public function indexAction(){        
        if ($this->_request->isPost()){
            $para = $this->_request->getParams();
            $mailconfig = $this->getFrontController()->getParam("bootstrap")->getOption('mailconfig');            
            $mail = $this->getFrontController()->getParam("bootstrap")->getOption('mail');

            $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailconfig);

            $sendmail = new Zend_Mail('utf-8');
            $sendmail->setBodyText($this->mailbody($para));
            $sendmail->setFrom($mail['sender'], $mail['sender_name']);
            $sendmail->addTo($mail['replytovietlinh'], $mail['replytovietlinhName']);
            $sendmail->setSubject($mail['subject']);
            try{
                $sendmail->send($transport);
            }  catch (Zend_Mail_Exception $e){
                die("Chet Em Roi");
            }
        }
        $contentOb = new Henry_Contents();
        $tmp = $contentOb->find("contact","vi")->toArray();
        $this->view->rightContent = html_entity_decode($tmp[0]['contents_des']);
    }
    public function mailbody($para){
        $output = "
            Thông tin khách hàng gửi mail từ Website
            Họ tên: {$para['hoten']}
            Công ty: {$para['congty']}
            Địa chỉ: {$para['diachi']}
            Email: {$para['email']}
            Điện thoại: {$para['dienthoai']}
            Fax: {$para['fax']}
            Nội dung: {$para['noidung']}
        ";
        return $output;
    }
}
